package com.weme.mine.dialog

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.gson.Gson
import com.weme.common.base.BaseDialog
import com.weme.common.util.setOnFastClickListener
import com.weme.common.util.visible
import com.weme.common.network.BIND_TYPE
import com.weme.common.util.AppMkHelper
import com.weme.mine.R
import com.weme.mine.databinding.DialogAccountBindBinding

class BindAccountDialog(val callback: (Boolean) -> Unit) : BaseDialog() {


    override fun onStart() {
        super.onStart()
        dialog?.window?.apply {
            attributes.windowAnimations = com.weme.common.R.style.DialogAnimation
            attributes.gravity = Gravity.BOTTOM
            setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
            setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }

    }

    private lateinit var binding: DialogAccountBindBinding
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
        super.onCreate(savedInstanceState)
        binding = DialogAccountBindBinding.inflate(LayoutInflater.from(context), null, false) //   giftAdapter = GiftAdapter(requireContext(),listOf("", "", "", "", ""))

        binding.calGoogle.setOnFastClickListener{
            callback.invoke(true)
            dismiss()
        }
        val loginType =  AppMkHelper.decodeString(BIND_TYPE)
        val parsedArray = Gson().fromJson(loginType, IntArray::class.java)
        parsedArray.forEach {
            when (it) {
                1 -> binding.calGoogle.visible()
                2 -> binding.calFb.visible()
            }
        }
        return binding.root
    }

}